import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import viteCompression from 'vite-plugin-compression'

export default defineConfig({
  envDir: 'environment',
  base: './',
  plugins: [vue(), vueJsx(), viteCompression({
    filter: /.(js|css|html|json|mjs|png|jpg|jpeg|svg)$/i
  })],
  publicDir: './public',
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      'vue-i18n': 'vue-i18n/dist/vue-i18n.esm-bundler.js'
    },
    extensions: ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json', '.vue']
  },
  server: {
    proxy: {
      '/v1/api': {
        target: 'http://127.0.0.1:8771/api',
        rewrite: (path) => path.replace(/^\/v1\/api/, '')
      }
    }
  },
  build: {
    outDir: 'dist',
    assetsDir: 'public',
    assetsInlineLimit: 4096,
    chunkSizeWarningLimit: 500,
    rollupOptions: {
      output: {
        compact: true,
        manualChunks: (id) => {
          if (id.includes('node_modules')) {
            return 'modules'
          }
        }
      }
    }
  },
  optimizeDeps: {
    include: ['jsoneditor']
  }
})
